package com.feel.controller;

import com.feel.pojo.Appointment;
import com.feel.pojo.RespBean;
import com.feel.service.AppointmentService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 刘永钦
 * @Date: 2024-09-04-16:46
 * @Description:
 */
@RestController
@RequestMapping("/admin/appointment")
public class AppointmentController {
    @Autowired
    private AppointmentService appointmentService;

    /**
     * 分页查找订饭
     */
    @GetMapping
    RespBean getAll(Integer page, Integer userId, Integer empId, Integer typeId,Integer departmentId) {
        if (page == null || page <= 0) {
            page = 1;
        }
        Appointment appointment = new Appointment();
        appointment.setUserId(userId);
        appointment.setEmpId(empId);
        appointment.setTypeId(typeId);
        appointment.setDepartmentId(departmentId);

        PageInfo<Appointment> list = appointmentService.getAll(page, appointment);

        return RespBean.ok("查询成功", list);
    }

    /**
     * 新增订单
     */
    @PostMapping
    RespBean addInfo(@RequestBody Appointment appointment) {
        appointment.setAppointmentStatus(0);
        appointment.setSpeed("1");
        Boolean b = appointmentService.addInfo(appointment);
        return b ? RespBean.ok("添加成功") : RespBean.error("添加失败");
    }

    /**
     * 修改订单
     */
    @PutMapping
    RespBean updateInfo(@RequestBody Appointment appointment) {
        Boolean b = appointmentService.updateInfo(appointment);
        return b ? RespBean.ok("更新成功") : RespBean.error("更新失败");
    }

    /**
     * 删除订单
     */
    @DeleteMapping("/{id}")
    RespBean delInfo(@PathVariable("id") Integer id) {
        Boolean b = appointmentService.delInfo(id);
        return b ? RespBean.ok("删除成功") : RespBean.error("删除失败");
    }

    /**
     * 通过id查询
     */
    @GetMapping("/{id}")
    RespBean getById(@PathVariable("id")Integer id) {
        Appointment appointment = appointmentService.getById(id);
        return RespBean.ok("查询成功", appointment);
    }
    /**
     * 完成订单请求
     */
    @PutMapping("/finsh")
    RespBean completeTheOrder(Integer id) {
        Appointment appointment = new Appointment();
        appointment.setAppointmentId(id);
        appointment.setSpeed("10");
        appointment.setAppointmentStatus(3);
        Boolean b = appointmentService.updateInfo(appointment);
        return b ? RespBean.ok("更新成功") : RespBean.error("更新失败");
    }
}
